package com.huawei.hianalytics.f.f;

import android.content.Context;
import android.content.SharedPreferences;
import com.huawei.hianalytics.f.b.g;
import com.huawei.hianalytics.f.g.h;
import com.huawei.hianalytics.f.g.i;
import com.huawei.hianalytics.f.g.j;
import com.huawei.hianalytics.f.g.k;
import com.huawei.hianalytics.g.b;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.json.JSONObject;

class a implements h {
    private l a;
    private Context b;
    private String c;
    private String d;
    private String e;
    private List<com.huawei.hianalytics.f.b.a> f;
    private String g = "";

    a(Context context, List<com.huawei.hianalytics.f.b.a> list, String str, String str2, String str3, String str4) {
        this.b = context;
        this.f = list;
        this.d = str;
        this.a = n.a();
        this.c = str2;
        this.e = str3;
        this.g = str4;
    }

    private boolean a(g gVar) {
        boolean z = false;
        JSONObject c = gVar.c();
        if (c == null) {
            b.b("HiAnalytics/event", "appActionDatas is null, no data report");
        } else {
            try {
                byte[] a = i.a(c.toString().getBytes("UTF-8"));
                SharedPreferences d = h.d(this.b, "global_v2");
                Object a2 = j.a(this.c, this.d, this.g);
                b.b("DataSendTask", "Record the data reqID being reported,reqID: " + a2);
                h.a(d, "request_id", a2);
                b.b("DataSendTask", "number of events per request: " + this.f.size());
                z = this.a.a(a, this.d, this.c, this.g);
            } catch (UnsupportedEncodingException e) {
                b.c("DataSendTask", "sendData():  getBytes - Unsupported coding format!!");
            }
        }
        return z;
    }

    public void run() {
        b.b("HiAnalytics/event", " begin to send event data TYPE : %s, TAG : %s ,reqID:" + this.g, this.d, this.c);
        if ("preins".equals(this.d) && com.huawei.hianalytics.a.b.j().length == 0) {
            b.b("HiAnalytics/event", "upload url now : preins ,reqID:" + this.g);
            new p(this.b).a();
        }
        g a = o.a(this.f, this.d, this.c, this.e, this.g, this.b);
        com.huawei.hianalytics.f.b.a[] b = a.b();
        if (b.length == 0) {
            b.c("DataSendTask", "Data is out of date and no data is reported.reqID:" + this.g);
            return;
        }
        b.b("HiAnalytics/event", "data send result: %s ,reqID:" + this.g, Boolean.valueOf(a.a() != null ? a(a) : false));
        if (a.a() != null ? a(a) : false) {
            h.e(this.b, j.a(this.c, this.d, this.g));
        } else {
            k.a(new g(this.b, b, this.c, this.d, this.g));
        }
    }
}
